import { EAnswerState, type MainItemVo } from '@/api/type'
import { computed } from 'vue'

export function useMessageHook(chat: MainItemVo) {
  const { contentType, type, responseState, isLoading: isLoading, error, answerState } = chat
  const isClear = computed(() => contentType === 'clear')
  const isAnswer = computed(() => type === 'received')
  const isQuestion = computed(() => type === 'sent')
  const stateClass = computed(() => {
    return {
      'last-one': chat.isLastOne,
      'input-by-one': isClear.value || !chat.isLastOne || !isAnswer.value || chat.replyState,
      answer: isAnswer.value,
      question: isQuestion.value,
      clear: isClear.value,
      loading: isLoading,
      error,
      'net-error':
        responseState === '2' || responseState === '3' || answerState === EAnswerState.OVERTIME
    }
  })

  return {
    isClear,
    isAnswer,
    isQuestion,
    stateClass
  }
}
